<template>
  <div class="flex-start">
    <div class="m-r-30" v-for="(item,index) in options" :key="index">
      <el-radio v-model="value" :label="item.value" @change="changeValue" :disabled="disabled">{{ item.label }}</el-radio>
    </div>
  </div>
</template>

<script>
import {getRespData, isNotNull} from "@/util/common-util";
import {getChildList} from "@/api/business/dict";

export default {
  name: "app-radio-group",
  props: {
    disabled:{
      type: Boolean,
      default: false
    },
    initValue: {
      type: Object,
      default: null
    },
    dictCode: {
      type: String,
      default: ''
    },
  },
  data() {
    return {
      options: [],
      value: ''
    }
  },
  created() {
    this.initOptions(() => {
      this.value = this.initValue
    })
  },
  methods: {
    initOptions(success) {
      this.options = []
      getChildList(this.dictCode).then(res => {
        for (const item of getRespData(res)) {
          this.options.push({
            label: item.dictValue,
            value: item.dictKey,
          })
        }
        success && success()
      })
    },
    changeValue() {
      this.$emit('change', this.value)
    }
  }
}
</script>

